using System;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.HomeServer.Controls;

namespace Microsoft.HomeServer.HomeServerConsoleTab.TV4Home.Server.WHS.AddIn.HomeServerControlsWrapper
{
    public class HtmlLinkPanelWrapper : UserControl
    {
        string _linkText = "Click here to open the link";
        string _url = "http://";

        public HtmlLinkPanelWrapper()
        {
            SetupBrowserLink();
        }

        [Localizable(true)]
        public string LinkText
        {
            get { return _linkText; }
            set { _linkText = value; SetupBrowserLink(); }
        }

        [Localizable(true)]
        public string URL
        {
            get { return _url; }
            set { _url = value; SetupBrowserLink(); }
        }

        private void SetupBrowserLink()
        {
            Control ctrl;

            this.Controls.Clear();

            try
            {
                ctrl = new HtmlLinkPanel(_linkText, _url);
            }
            catch (Exception ex)
            {
                // design time throws an exception due to accessing a resource that requires admin privileges (problem in HomeServerControls.dll)
                if (ex.InnerException is UnauthorizedAccessException)
                    ctrl = new Label { Text = @"Designer support: run VS as admin." };
                else
                    throw;
            }

            ctrl.SetBounds(0, 0, this.Width, this.Height);

            this.Controls.Add(ctrl);
        }
    }
}